package net.yla.smartbus.module.controller.web.ba.SendSMS;

import net.yla.smartbus.core.api.ApiResult;
import net.yla.smartbus.core.base.BaseController;
import net.yla.smartbus.module.ba.SendSMS.service.SendSMSService;
import net.yla.smartbus.module.ba.smsMessages.form.SmsMessagesForm;
import net.yla.smartbus.module.ba.smsMessages.query.CaptchaQuery;
import net.yla.smartbus.module.ba.smsMessages.query.SmsMessagesQuery;
import net.yla.smartbus.module.ba.smsMessages.serivce.SmsMessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:LiuJie
 * @date:2020/8/17
 * @description:发送验证码
 */
@RestController
@RequestMapping("/api/web/sms")
public class SendSMSController extends BaseController {

    @Autowired
    private SendSMSService sendSMSService;

    @Autowired
    private SmsMessagesService smsMessagesService;

    /**
     * 发送验证码
     *
     * @param phoneNo
     * @return
     */
    @PostMapping("/send")
    public ApiResult sendSms(String phoneNo) {
        return success(sendSMSService.sendSms(phoneNo));
    }

    /**
     * 校验验证码
     *
     * @param phoneNo
     * @param code
     * @return
     */
    @PostMapping("/checkCode")
    public ApiResult checkSms(String phoneNo, String code) {
        return success(sendSMSService.checkSms(phoneNo, code));
    }

    /**
     * 查询发送的信息集
     *
     * @param query
     * @return
     */
    @PostMapping("/query")
    public ApiResult listSendSmsMessages(SmsMessagesQuery query) {
        return success(smsMessagesService.listSendSmsMessages(query));
    }

    /**
     * 获取已发短信的记录数
     *
     * @param query
     * @return
     */
    @PostMapping("/count")
    public ApiResult querySms(SmsMessagesQuery query) {
        return success(smsMessagesService.selectSendSmsCount(query));
    }

    /**
     * 查看已发短信的信息
     *
     * @param smsId
     * @return
     */
    @PostMapping("/view")
    public ApiResult viewSms(Integer smsId) {
        return success(smsMessagesService.selectByPrimaryKey(smsId));
    }

    /**
     * 清理历史短消息发送日志
     *
     * @param query
     * @return
     */
        @PostMapping("/clean")
    public ApiResult cleanSms(SmsMessagesQuery query) {
        return success(smsMessagesService.cleanSmsMessages(query));
    }

}
